import Cookies from 'js-cookie'
import { defineStore } from 'pinia'

export default defineStore('app', {
  state() {
    return {
      sidebar: {
        opened: Cookies.get('sidebarStatus') ? Boolean(Number(Cookies.get('sidebarStatus'))) : true, // true 打开 false 关闭
      },
    }
  },

  actions: {
    toggle_sidebar(): void {
      this.sidebar.opened = !this.sidebar.opened
      if (this.sidebar.opened) {
        Cookies.set('sidebarStatus', '1')
      } else {
        Cookies.set('sidebarStatus', '0')
      }
    },
  },

  getters: {
    opened(): boolean {
      return this.sidebar.opened
    },
  },
})
